﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.LIB;

namespace HYFloorPipeModule
{
	public partial class HYHeatParamForm : System.Windows.Forms.Form
	{
		public HYHeatParamForm(string strHeatPipeType, string strHeatLayer, string strGroundLayer)
		{
			this.strHeatPipeType = strHeatPipeType;
			this.strHeatLayer = strHeatLayer;
			this.strGroundLayer = strGroundLayer;
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this.sqlHelper = new SQLiteDataBaseHelper(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3"));
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void HYHeatParamForm_Load(object sender, EventArgs e)
		{
			DataTable dataSource = SQLiteDataOperate.ExecQuery(string.Concat(new string[]
			{
				"select AverageWaterTemperature,IndoorAirTemperature,DIST100ClrfRdt,DIST100HeatLoss,DIST200ClrfRdt,DIST200HeatLoss,DIST300ClrfRdt,DIST300HeatLoss,DIST400ClrfRdt,DIST400HeatLoss,DIST500ClrfRdt,DIST500HeatLoss from ClrfRdt where Lagging='",
				this.strHeatLayer,
				"'and FloorMedium='",
				this.strGroundLayer,
				"'and PIPE='",
				this.strHeatPipeType,
				"'"
			}));
			this.dgvHeatParam.DataSource = dataSource;
			this.dgvHeatParam.Columns[0].DataPropertyName = "AverageWaterTemperature";
			this.dgvHeatParam.Columns[1].DataPropertyName = "IndoorAirTemperature";
			this.dgvHeatParam.Columns[2].DataPropertyName = "DIST100ClrfRdt";
			this.dgvHeatParam.Columns[3].DataPropertyName = "DIST100HeatLoss";
			this.dgvHeatParam.Columns[4].DataPropertyName = "DIST200ClrfRdt";
			this.dgvHeatParam.Columns[5].DataPropertyName = "DIST200HeatLoss";
			this.dgvHeatParam.Columns[6].DataPropertyName = "DIST300ClrfRdt";
			this.dgvHeatParam.Columns[7].DataPropertyName = "DIST300HeatLoss";
			this.dgvHeatParam.Columns[8].DataPropertyName = "DIST400ClrfRdt";
			this.dgvHeatParam.Columns[9].DataPropertyName = "DIST400HeatLoss";
			this.dgvHeatParam.Columns[10].DataPropertyName = "DIST500ClrfRdt";
			this.dgvHeatParam.Columns[11].DataPropertyName = "DIST500HeatLoss";
			for (int i = 0; i < 12; i++)
			{
				this.dgvHeatParam.Columns[i + 12].Visible = false;
			}
		}

		private void dgvHeatParam_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
		{
			if (e.ColumnIndex == 0 && e.RowIndex != -1)
			{
				using (Brush brush = new SolidBrush(this.dgvHeatParam.GridColor))
				{
					using (Brush brush2 = new SolidBrush(e.CellStyle.BackColor))
					{
						using (Pen pen = new Pen(brush))
						{
							e.Graphics.FillRectangle(brush2, e.CellBounds);
							if (e.RowIndex < this.dgvHeatParam.Rows.Count - 1 && this.dgvHeatParam.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString() != e.Value.ToString())
							{
								e.Graphics.DrawLine(pen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
							}
							e.Graphics.DrawLine(pen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom);
							if (e.Value != null && (e.RowIndex <= 0 || !(this.dgvHeatParam.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString() == e.Value.ToString())))
							{
								e.Graphics.DrawString((string)e.Value, e.CellStyle.Font, Brushes.Black, (float)(e.CellBounds.X + 2), (float)(e.CellBounds.Y + 5), StringFormat.GenericDefault);
							}
							e.Handled = true;
						}
					}
				}
			}
		}

		private SQLiteDataBaseHelper sqlHelper;

		private string strHeatPipeType = "";

		private string strHeatLayer = "";

		private string strGroundLayer = "";
	}
}
